package com.pinc.cpbl;

import java.io.IOException;
import java.io.InputStream;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Parse_AllstarResult extends MyHTMLparser {

	public Parse_AllstarResult(InputStream istream) {
		super(istream, "big5");
	}

	public boolean parse(StringBuilder html_str)
	{
		String str;
		boolean find=false;
		Pattern p = Pattern.compile("<!--END-->", Pattern.CASE_INSENSITIVE|Pattern.DOTALL);
		Matcher m;
		int bytes_read;

		try {
			do
			{
				bytes_read = readBytes(READ_LEN);
				str = new String(buf, 0, bytes_read, charset);
				m = p.matcher(str);
				if ( m.find())
				{
					find = true;
					break;
				}
				else
				{
					html_str = html_str.append(str);
				}
			}while( bytes_read == READ_LEN);
			if (find)
			{
				html_str = html_str.append(str.substring(0, m.start()));
				return true;
			}
			return false;
		} catch (IOException e) {
			e.printStackTrace();
			return false;
		}
	}
}
